package com.knoya.chejian.pda;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Application;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.Color;
import android.media.RingtoneManager;
import android.os.Build;
import android.util.DisplayMetrics;
import android.util.Log;

import com.knoya.chejian.pda.myclass.UnCeHandler;
import com.knoya.chejian.pda.util.Myutil;
import com.knoya.chejian.pda.util.Sputil;

import org.xutils.x;

import java.util.ArrayList;

/**
 * Created by Administrator on 2016/11/3 0003.
 */
public class Myapp extends Application {
    public static int mScreenWidth = 0;
    public static int mScreenHeight = 0;
    private static final String TAG = "Init";
    private static Context mContext;

    public static Context getContext() {
        return mContext;
    }

    public static SharedPreferences.Editor editor;//sp储存器
    public static SharedPreferences sp;//sp提取器

    @Override
    public void onCreate() {
        super.onCreate();
        init();
//        ReGengXing();
        x.Ext.init(this);
        x.Ext.setDebug(false);
        mContext = getApplicationContext();
        DisplayMetrics mDisplayMetrics = getApplicationContext().getResources()
                .getDisplayMetrics();
        Myapp.mScreenWidth = mDisplayMetrics.widthPixels;
        Myapp.mScreenHeight = mDisplayMetrics.heightPixels;
        editor = Sputil.editor("erp");
        sp = Sputil.sp("erp");
        editor.putBoolean("apd", isPad(this));
        editor.putBoolean("Sophix", false);
        editor.commit();
    }

    public static boolean isXing = false;

    public static boolean isPad(Context context) {
        return (context.getResources().getConfiguration().screenLayout
                & Configuration.SCREENLAYOUT_SIZE_MASK)
                >= Configuration.SCREENLAYOUT_SIZE_LARGE;
    }


    public static ArrayList<Activity> list = new ArrayList<Activity>();

    public void init() {
        //设置该CrashHandler为程序的默认处理器
        UnCeHandler catchExcep = new UnCeHandler(this);
        Thread.setDefaultUncaughtExceptionHandler(catchExcep);
    }

    /**
     * Activity关闭时，删除Activity列表中的Activity对象
     */
    public void removeActivity(Activity a) {
        list.remove(a);
    }

    /**
     * 向Activity列表中添加Activity对象
     */
    public void addActivity(Activity a) {
        list.add(a);
        Myutil.Mylog("TAAAAAG", list.toString());
    }

//    /**
//     * 关闭Activity列表中的所有Activity
//     */
//    public void finishActivity() {
//        for (Activity activity : list) {
//            if (null != activity) {
//                activity.finish();
//            }
//        }
//        //杀死该应用进程
//        android.os.Process.killProcess(android.os.Process.myPid());
//    }
}
